package com.sx.manage.controller.consumer.company.excel;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.common.util.NumberUtil;
import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.consumer.company.excel.MConsumerCompanyWebServiceImpl;
import com.sx.manage.service.consumer.company.excel.consumer.IMcompanyImportConsumerInfoService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.constants.type.consumer.MCompanyConsumersImportStatus;
import com.sx.model.manage.mybatis.form.company.MCompanyImportConsumerInfoForm;
import com.sx.model.manage.mybatis.vo.company.MCompanyImportConsumerInfoVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;

/**
 * 公司导入用户controller
 * 
 * @author lenovo
 *
 */
@Controller
@RequestMapping("/companyImportConsumer")
public class MCompanyImportConsumerController extends MBaseController {
	private Logger log = LoggerFactory.getLogger(this.getClass());
	// web service
	@Resource(name = "consumerCompanyWebServiceImpl")
	private MConsumerCompanyWebServiceImpl consumerCompanyWebServiceImpl;
	// service
	@Resource(name = "companyImportConsumerInfoServiceImpl")
	private IMcompanyImportConsumerInfoService companyImportConsumerInfoServiceImpl;

	/**
	 * 跳转到 普通用户列表界面
	 */
	@RequestMapping(value = "individualConsumer")
	public ViewAndModel individualConsumer() {
		ViewAndModel model = new ViewAndModel(request, cache);
		model.setViewName("consumer/company/excel/consumer_msg_chcek");

		return model;
	}

	/**
	 * 跳转到添加界面
	 */
	@RequestMapping(value = "toConsumerView")
	public ViewAndModel toConsumerView(Long consumer_id) {
		ViewAndModel model = new ViewAndModel(request, cache);
		model.setViewName("consumer/company/excel/consumer_view");
		MCompanyImportConsumerInfoVO consumerVO = companyImportConsumerInfoServiceImpl.query_by_id(consumer_id).getObjVo();
		model.addObject("consumerVO", consumerVO);
		model.addObject("view", "toView");
		return model;
	}

	/** 获取用户分页信息 */
	@RequestMapping(value = "pageConsumer")
	@ResponseBody
	public ResultListVO<MCompanyImportConsumerInfoVO> page(MCompanyImportConsumerInfoForm form) {
		log.info("导入公司用户数据列表form={}", form);
		List<MCompanyConsumersImportStatus> import_status_list = new ArrayList<>(1);
		import_status_list.add(MCompanyConsumersImportStatus.PLATFORM_AUDIT);

		form.setImport_status_list(import_status_list);
		form.setImport_status(null);
		return companyImportConsumerInfoServiceImpl.query_page(form);
	}

	/**
	 * 人工验证通过三要素验证
	 * 
	 * @param consumer_id
	 * @return
	 */
	@RequestMapping(value = "artificialKeyValidate")
	@ResponseBody
	public ResultBooleanVO artificialKeyValidate(Long[] consumer_ids) {
		log.info("导入公司用户人工三要素验证consumer_ids={}", NumberUtil.arrayToStr(consumer_ids));
		return this.consumerCompanyWebServiceImpl.edit_validate_batch(consumer_ids, loginConsumer());
	}

	/**
	 * 用户三要素信息验证(新的华夏接口)
	 * 
	 * @param consumer_id
	 * @return
	 */
	@RequestMapping({ "threeElementsConsumer" })
	@ResponseBody
	public ResultBooleanVO threeElementsConsumer(Long[] consumer_ids) {
		log.info("导入公司用户三要素验证consumer_ids={}", NumberUtil.arrayToStr(consumer_ids));
		return consumerCompanyWebServiceImpl.threeElements(consumer_ids, this.loginConsumer());
	}

}
